*you will need to install the following packages:
findit xtscc 
findit vioplot

*Then you will need to open the dataset: 03_BischofFinkSPSR2015.dta
use "03_BischofFinkSPSR2015.dta"

*all tables

*Arrange sample size:
xi: xtscc BFconflictindex i.monarch_2 lrepression lrepression2 tfi i.persian_gulf percent_muslim_menaldo log_population log_area ef pci i.fullregime_dummy if region_world_2_2010_b == 3 & year > 1976 & year <2007, lag(1)
keep if e(sample)

*Table 1
*Menaldo
xi: xtscc BFconflictindex i.monarch_2 tfi i.persian_gulf percent_muslim_menaldo log_population log_area ef pci i.fullregime_dummy if region_world_2_2010_b == 3 & year > 1976 & year <2007, lag(1)
outreg2 using table1.xls, alpha(0.001, 0.01, 0.05) title(table1) ctitle(1) addstat(ad, e(r2)) nocons auto(2) bdec(2) word 

*Menaldo+Rep
xi: xtscc BFconflictindex i.monarch_2 lrepression lrepression2 tfi i.persian_gulf percent_muslim_menaldo log_population log_area ef pci i.fullregime_dummy if region_world_2_2010_b == 3 & year > 1976 & year <2007, lag(1)
outreg2 using table1.xls, alpha(0.001, 0.01, 0.05) title(table1) ctitle(2) addstat(ad, e(r2)) nocons auto(2) bdec(2) word 

*Menaldo+Rep-TFI
xi: xtscc BFconflictindex i.monarch_2 lrepression lrepression2 i.persian_gulf percent_muslim_menaldo log_population log_area ef pci i.fullregime_dummy if region_world_2_2010_b == 3 & year > 1976 & year <2007, lag(1)
outreg2 using table1.xls, alpha(0.001, 0.01, 0.05) title(table1) ctitle(3) addstat(ad, e(r2)) nocons auto(2) bdec(2) word 

*Menaldo+Rep-TFI-Persian Gulf
xi: xtscc BFconflictindex i.monarch_2 lrepression lrepression2 percent_muslim_menaldo log_population log_area ef pci i.fullregime_dummy if region_world_2_2010_b == 3 & year > 1976 & year <2007, lag(1)
outreg2 using table1.xls, alpha(0.001, 0.01, 0.05) title(table1) ctitle(4) addstat(ad, e(r2)) nocons auto(2) bdec(2) word

*Menaldo+Rep-TFI-Persian Gulf-%Muslims
xi: xtscc BFconflictindex i.monarch_2 lrepression lrepression2 log_population log_area ef pci i.fullregime_dummy if region_world_2_2010_b == 3 & year > 1976 & year <2007, lag(1)
outreg2 using table1.xls, alpha(0.001, 0.01, 0.05) title(table1) ctitle(5) addstat(ad, e(r2)) nocons auto(2) bdec(2) word

*PCSE
xi: xtpcse BFconflictindex lBFconflictindex lrepression lrepression2 i.monarch_2 tfi log_population log_area percent_muslim_menaldo ef pci i.persian_gulf i.fullregime_dummy  if region_world_2_2010_b == 3 & year > 1976 & year <2007
outreg2 using table1.xls, alpha(0.001, 0.01, 0.05) title(table1) ctitle(6) addstat(ad, e(r2)) nocons auto(2) bdec(2) word



*Table 2

** Name: Table2_neu
local name Table2_neu.xls
*** list of dependent variables:
local av revolutions_binary govtcrises_binary guerillawarfare_binary assassinations_binary antigovtdemonst_binary  riots_binary strikes_binary
***  controls as in Menaldo's online appendix P.20:
local controlsmenaldo monarch_2 logarithmic_growth_imp tfi pci log_population log_area percent_muslim_menaldo ef persian_gulf fullregime_dummy yearorth1 yearorth2 yearorth3
*** Repression
local repression lrepression2 lrepression
*** options for regression  
local regressionoptions if region_world_2_2010_b == 3 & year > 1976 & year <2007, cluster(year)

*** immer wiederkehrende Optionen fuer outreg2 (das bl�de ctitle(1) muss hin, damit outreg2 nicht immer den vollen Namen der AV oben hinschreibt. Man k�nnte (" ") als ctitle angeben, aber dann sieht es im Texteditor Mist aus.
local outregoptions using `name', title(`name') ctitle(1) addstat(Pseudo R�, e(r2_p)) nocons auto(2) bdec(2) word 


*** OK. Dann machen wir �ber alle die definieren AVs hinweg das, was Menaldo Table 3 auch macht.

foreach variable of varlist `av' {

probit `variable' `repression'  `controlsmenaldo' `regressionoptions'

outreg2 `repression'  `controlsmenaldo' `outregoptions' 

}


*Table 3 Robust

*Menaldo+linear rep
xi: xtscc BFconflictindex i.monarch_2 lrepression lrepression2 tfi i.persian_gulf percent_muslim_menaldo log_population log_area ef pci i.fullregime_dummy if region_world_2_2010_b == 3 & year > 1976 & year <2007, lag(1)
outreg2 using table3.xls, alpha(0.001, 0.01, 0.05) title(table1) ctitle("linear") addstat(ad, e(r2)) nocons auto(2) bdec(2) word  

*Menaldo+CFE
xi: xtscc BFconflictindex i.monarch_2 lrepression lrepression2 tfi i.persian_gulf percent_muslim_menaldo log_population log_area ef pci i.fullregime_dummy i.hmccode if region_world_2_2010_b == 3 & year > 1976 & year <2007, lag(1)
outreg2 using table3.xls, alpha(0.001, 0.01, 0.05) title(table1) ctitle("Driscool+CFE") addstat(ad, e(r2)) nocons auto(2) bdec(2) word 

*Menaldo+YFE
xi: xtscc BFconflictindex i.monarch_2 lrepression lrepression2 tfi i.persian_gulf percent_muslim_menaldo log_population log_area ef pci i.fullregime_dummy i.year if region_world_2_2010_b == 3 & year > 1976 & year <2007, lag(1)
outreg2 using table3.xls, alpha(0.001, 0.01, 0.05) title(table1) ctitle("Driscool+YFE") addstat(ad, e(r2)) nocons auto(2) bdec(2) word  

*Menaldo+jackknife
xi: jackknife, cluster(hmccode): xtscc BFconflictindex i.monarch_2 lrepression lrepression2 tfi i.persian_gulf percent_muslim_menaldo log_population log_area ef pci i.fullregime_dummy if region_world_2_2010_b == 3 & year > 1976 & year <2007, lag(1)
outreg2 using table3.xls, alpha(0.001, 0.01, 0.05) title(table1) ctitle("Driscool+jackknife") addstat(ad, e(r2)) nocons auto(2) bdec(2) word  

*PCSE+CFE
xi: xtpcse BFconflictindex i.monarch_2 lrepression lrepression2 tfi i.persian_gulf percent_muslim_menaldo log_population log_area ef pci i.fullregime_dummy l.BFconflictindex i.hmccode if region_world_2_2010_b == 3 & year > 1976 & year <2007, c(ar1)
outreg2 using table3.xls, alpha(0.001, 0.01, 0.05) title(table1) ctitle("PCSE+CFE") addstat(ad, e(r2)) nocons auto(2) bdec(2) word 

*PCSE+Year
xi: xtpcse BFconflictindex i.monarch_2 lrepression lrepression2 tfi i.persian_gulf percent_muslim_menaldo log_population log_area ef pci i.fullregime_dummy  l.BFconflictindex i.year if region_world_2_2010_b == 3 & year > 1976 & year <2007, c(ar1)
outreg2 using table3.xls, alpha(0.001, 0.01, 0.05) title(table1) ctitle("PCSE+YFE") addstat(ad, e(r2)) nocons auto(2) bdec(2) word 

*PCSE+Repression Dummy
*xi: xtpcse BFconflictindex lBFconflictindex i.lrepression i.monarch_2 tfi log_population log_area percent_muslim_menaldo ef pci i.persian_gulf i.fullregime_dummy  if region_world_2_2010_b == 3 & year > 1976 & year <2007
*outreg2 using table3.xls, alpha(0.001, 0.01, 0.05) title(table1) ctitle("PCSE+Repression Dummy") addstat(ad, e(r2)) nocons auto(2) bdec(2) word 


***********SUMMARY TABLE+++++++++++++
xtsum BFconflictindex monarch_2 lrepression tfi log_population log_area percent_muslim_menaldo ef pci persian_gulf fullregime_dummy if region_world_2_2010_b == 3 & year > 1977 & year <2007





******Graphs+Figures

************Results Conflitindex modell********
*Arrange sample size:
xi: xtscc BFconflictindex i.monarch_2 lrepression lrepression2 tfi i.persian_gulf percent_muslim_menaldo log_population log_area ef pci i.fullregime_dummy if region_world_2_2010_b == 3 & year > 1976 & year <2007, lag(1)
keep if e(sample)
xi: xtpcse BFconflictindex lBFconflictindex monarch_2 c.lrepression##c.lrepression tfi log_population log_area percent_muslim_menaldo ef pci persian_gulf fullregime_dummy if region_world_2_2010_b == 3 & year > 1977 & year <2007, noconstant
margins, at(lrepression=(1(1)5))  at((mean) lBFconflictindex tfi log_population log_area percent_muslim_menaldo ef pci monarch_2=0 persian_gulf=0 fullregime_dummy=0) 
marginsplot, recast(scatter) recastci(rcap) legend(off) ytitle("Conflict-Index (Fitted Values)") xtitle("Repression lagged")

*************Results BDV GRAPHISCH************

probit revolutions_binary monarch_2 c.lrepression##c.lrepression logarithmic_growth_imp tfi pci log_population log_area percent_muslim_menaldo ef persian_gulf fullregime_dummy yearorth1 yearorth2 yearorth3 if region_world_2_2010_b == 3 & year > 1977 & year <2007, cluster(year)
margins, at(lrepression=(1(1)5))  at((mean) tfi log_population log_area percent_muslim_menaldo ef pci yearorth1 yearorth2 yearorth3 monarch=0 persian_gulf=0 fullregime_dummy=0) 
marginsplot, recast(scatter) recastci(rcap) xtitle("") ytitle("") name(rev) title("Revolution") legend(off)
probit govtcrises_binary c.lrepression##c.lrepression monarch_2 logarithmic_growth_imp tfi pci log_population log_area percent_muslim_menaldo ef persian_gulf fullregime_dummy yearorth1 yearorth2 yearorth3 if region_world_2_2010_b == 3 & year > 1977 & year <2007, cluster(year)
margins, at(lrepression=(1(1)5))  at((mean) tfi log_population log_area percent_muslim_menaldo ef pci yearorth1 yearorth2 yearorth3 monarch=0 persian_gulf=0 fullregime_dummy=0) 
marginsplot, recast(scatter) recastci(rcap) xtitle("") ytitle("") name(cri) title("Crisis") legend(off)
probit guerillawarfare_binary c.lrepression##c.lrepression monarch_2 logarithmic_growth_imp tfi pci log_population log_area percent_muslim_menaldo ef persian_gulf fullregime_dummy yearorth1 yearorth2 yearorth3 if region_world_2_2010_b == 3 & year > 1977 & year <2007, cluster(year)
margins, at(lrepression=(1(1)5))  at((mean) tfi log_population log_area percent_muslim_menaldo ef pci yearorth1 yearorth2 yearorth3 monarch=0 persian_gulf=0 fullregime_dummy=0) 
marginsplot, recast(scatter) recastci(rcap) xtitle("") ytitle("") name(gur) title("Guerilla Warfare") legend(off)
probit assassinations_binary c.lrepression##c.lrepression monarch_2 logarithmic_growth_imp tfi pci log_population log_area percent_muslim_menaldo ef persian_gulf fullregime_dummy yearorth1 yearorth2 yearorth3 if region_world_2_2010_b == 3 & year > 1977 & year <2007, cluster(year)
margins, at(lrepression=(1(1)5))  at((mean) tfi log_population log_area percent_muslim_menaldo ef pci yearorth1 yearorth2 yearorth3 monarch=0 persian_gulf=0 fullregime_dummy=0) 
marginsplot, recast(scatter) recastci(rcap) xtitle("") ytitle("") name(asa) title("Assassination") legend(off)
probit antigovtdemonst_binary c.lrepression##c.lrepression monarch_2 logarithmic_growth_imp tfi pci log_population log_area percent_muslim_menaldo ef persian_gulf fullregime_dummy yearorth1 yearorth2 yearorth3 if region_world_2_2010_b == 3 & year > 1977 & year <2007, cluster(year)
margins, at(lrepression=(1(1)5))  at((mean) tfi log_population log_area percent_muslim_menaldo ef pci yearorth1 yearorth2 yearorth3 monarch=0 persian_gulf=0 fullregime_dummy=0) 
marginsplot, recast(scatter) recastci(rcap) xtitle("") ytitle("") name(ant) title("Demonstration") legend(off)
probit riots_binary c.lrepression##c.lrepression monarch_2 logarithmic_growth_imp tfi pci log_population log_area percent_muslim_menaldo ef persian_gulf fullregime_dummy yearorth1 yearorth2 yearorth3 if region_world_2_2010_b == 3 & year > 1977 & year <2007, cluster(year)
margins, at(lrepression=(1(1)5))  at((mean) tfi log_population log_area percent_muslim_menaldo ef pci yearorth1 yearorth2 yearorth3 monarch=0 persian_gulf=0 fullregime_dummy=0) 
marginsplot, recast(scatter) recastci(rcap) xtitle("") ytitle("") name(rio) title("Riot") legend(off)
probit strikes_binary c.lrepression##c.lrepression monarch_2 logarithmic_growth_imp tfi pci log_population log_area percent_muslim_menaldo ef persian_gulf fullregime_dummy yearorth1 yearorth2 yearorth3 if region_world_2_2010_b == 3 & year > 1977 & year <2007, cluster(year)
margins, at(lrepression=(1(1)5))  at((mean) tfi log_population log_area percent_muslim_menaldo ef pci yearorth1 yearorth2 yearorth3 monarch=0 persian_gulf=0 fullregime_dummy=0) 
marginsplot, recast(scatter) recastci(rcap) xtitle("") ytitle("") name(str) title("Strikes") legend(off)
graph combine rev cri gur asa ant rio str
graph drop rev cri gur asa ant rio str

**************Comparison between dummy and squared***********
*****CPS: Dummy critique:
****Let's see how the dummys look like:

*reanalyse with i.
xtpcse BFconflictindex lBFconflictindex i.lrepression i.monarch_2 tfi log_population log_area percent_muslim_menaldo ef pci i.persian_gulf i.fullregime_dummy  if region_world_2_2010_b == 3 & year > 1976 & year <2007
margins lrepression, at((mean) lBFconflictindex tfi log_population log_area percent_muslim_menaldo ef pci monarch=0 persian_gulf=0 fullregime_dummy=0)  
marginsplot, recast(scatter) recastci(rcap) xtitle("Repression lagged") ytitle("Conflict-Index (Fitted Values)") name(dum) title("Dummies") 

xi: xtpcse BFconflictindex lBFconflictindex monarch_2 c.lrepression##c.lrepression tfi log_population log_area percent_muslim_menaldo ef pci persian_gulf fullregime_dummy if region_world_2_2010_b == 3 & year > 1977 & year <2007, noconstant
margins, at(lrepression=(1(1)5))  at((mean) lBFconflictindex tfi log_population log_area percent_muslim_menaldo ef pci monarch=0 persian_gulf=0 fullregime_dummy=0)  
marginsplot, recast(scatter) recastci(rcap) xtitle("Repression lagged") ytitle("") name(squ) title("Polynomial") 
graph combine dum squ,
graph drop dum squ


***Figures:
vioplot repression, over(monarch_2) horizontal ylabel(, angle(horizontal)) xtitle(repression)  




